package com.yxj03;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerDemo {
    public static void main(String[] args) {
        //创建HashMap集合
        HashMap<Integer, String> hm = new HashMap<Integer, String>();
        //创建ArrayList，存储编号
        ArrayList<Integer> array = new ArrayList<Integer>();
        //创建花色数组和点数数组
        String[] colors = {"♦","♥","♠","♣"};
        //定义点数数组
        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //从0开始往HashMap里面存储编号，并存储对于的牌，同时往ArrayList里面存储编号
        int index = 0;
        for(String number : numbers) {
            for(String color : colors) {
                hm.put(index,color+number);
                array.add(index);
                index++;
            }
        }
        hm.put(index,"小王");
        array.add(index);
        index++;
        hm.put(index,"大王");
        array.add(index);
        //洗牌，洗的是编号,用Collections的shuffle方法
        Collections.shuffle(array);
        //发牌，发的也是编号，为了保证编号是排序的，创建TreeSet集合接收
        TreeSet<Integer> yxjArray = new TreeSet<Integer>();
        TreeSet<Integer> ymmArray = new TreeSet<Integer>();
        TreeSet<Integer> yxxArray = new TreeSet<Integer>();
        TreeSet<Integer> dpArray = new TreeSet<Integer>();
        for(int i = 0; i < array.size(); i++) {
            int x = array.get(i);
            if(i >= array.size()-3) {
                dpArray.add(x);
            }else if(i % 3 == 0) {
                yxjArray.add(x);
            }else if(i % 3 == 1) {
                ymmArray.add(x);
            }else if(i % 3 == 2) {
                yxxArray.add(x);
            }
        }
        //调用看牌方法看牌
        lookPoker("杨雪娇",yxjArray,hm);
        lookPoker("杨美美",ymmArray,hm);
        lookPoker("杨晓曦",yxxArray,hm);
        lookPoker("底牌",dpArray,hm);
    }
    //定义方法看牌，遍历TreeSet集合，获取编号，到HashMap集合找对应的牌
    public static void lookPoker(String name, TreeSet<Integer> ts, HashMap<Integer,String> hm) {
        System.out.println(name+"的牌是：");
        for(Integer key : ts) {
            String poker = hm.get(key);
            System.out.print(poker+" ");
        }
        System.out.println();
    }
}
